/*
 * loader_md.c
 *
 *  Created on: 2009-12-1
 *      Author: Bearice
 */
#include <vm.h>
#include <loader.h>
#include <winsock.h>
inline char* consumeBytes(PLOADER_STAT stat,int32 len){
	if(stat->left<len)
		return 0;
	stat->left -= len;
	char* ret = stat->ptr;
	stat->ptr += len;
	return ret;
}
inline uint64 readUInt64(PLOADER_STAT stat){
	return (uint64)readUInt32(stat)|(uint64)readUInt32(stat)<<32;
}
inline int64 readInt64(PLOADER_STAT stat){
	return readUInt64(stat);
}
inline uint32 readUInt32(PLOADER_STAT stat){
	return avm_ntohl(*(uint32*)consumeBytes(stat,4));
}
inline int32 readInt32(PLOADER_STAT stat){
	return avm_ntohl(*(int32*)consumeBytes(stat,4));
}
inline uint16 readUInt16(PLOADER_STAT stat){
	return avm_ntohs(*(uint16*)consumeBytes(stat,2));
}
inline int16 readInt16(PLOADER_STAT stat){
	return avm_ntohs(*(int16*)consumeBytes(stat,2));
}
inline uint8 readUInt8(PLOADER_STAT stat){
	return *(uint8*)consumeBytes(stat,1);
}
inline int8 readInt8(PLOADER_STAT stat){
	return *(int8*)consumeBytes(stat,1);
}
inline uint64 avm_ntohll(uint64 val){
	uint64 h = (uint64)(ntohl(val)&0xFFFFFFFF);
	uint64 l = (uint64)(ntohl(val>>32)&0xFFFFFFFF);
	return (h<<32)|l;
}
inline uint32 avm_ntohl(uint32 val){
	return ntohl(val);
}
inline uint16 avm_ntohs(uint16 val){
	return ntohs(val);
}
